//----------------Sonic CD Act Finish Script------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.Value0			:	Object.Timer

// All texts have their own X Position values
#alias Object.XPos  			:	Object.LineXPos0	// "SONIC GOT" Line
#alias Object.Value1			:	Object.LineXPos1	// "THROUGH ZONE X" Line
#alias Object.Value2			:	Object.LineXPos2	// Score Line
#alias Object.Value3			:	Object.LineXPos3	// Ring Bonus Line
#alias Object.Value4			:	Object.LineXPos4	// Time Bonus Line

#alias Object.Value5			:	Object.TimeBonus
#alias Object.Value6			:	Object.RingBonus

// New to Origins!
// The Stage List Pos of the current stage's Present version
#alias Object.Value7			:	Object.StagePosP

// HUD Alias
#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod

// Player Aliases
#alias Object[0].Type  			:	Player.Type
#alias Object[0].Value0			:	Player.Rings

// States
#alias -1	:	ACTFINISH_NULL				// Origins exclusive

#alias 0	:	ACTFINISH_INIT
#alias 1	:	ACTFINISH_SLIDEIN
#alias 2	:	ACTFINISH_DISPLAYTALLY
#alias 3	:	ACTFINISH_TALLYUP
#alias 4	:	ACTFINISH_DISPLAYFINAL
#alias 5	:	ACTFINISH_FADEOUT

#alias 6	:	ACTFINISH_HOLDOVERRESTART	// Origins exclusive
#alias 7	:	ACTFINISH_WAITFORCALLBACK	// Origins exclusive


#alias 0	:	PLAYER_SONIC_A
#alias 1	:	PLAYER_TAILS_A


// Time Period Aliases
#alias 0	:	TIME_PRESENT
#alias 1	:	TIME_PAST
#alias 2	:	TIME_GOOD_FUTURE
#alias 3	:	TIME_BAD_FUTURE

// Global SFX
#alias 16	:	SFX_G_SCOREADD
#alias 17	:	SFX_G_SCORETOTAL
#alias 19	:	SFX_G_SPECIALWARP

// Soundtrack
#alias 0	:	OST_JP

// How long the Zone Complete jingle for each soundtrack is
#alias 299	:	JP_ZONECOMPLETE_LENGTH
#alias 429	:	US_ZONECOMPLETE_LENGTH

// Callbacks Aliases
#alias 11	:	CALLBACK_TRIAL_ENDED

// Game Modes
#alias 1	:	MODE_SAVEGAME
#alias 2	:	MODE_TIMEATTACK
#alias 3	:	MODE_TRIAL

// Presentation List Stages
#alias 0 	:	STAGE_P_TITLE
#alias 2 	:	STAGE_P_TATTACK
#alias 11	:	STAGE_P_DOWNLOADSCREEN

// Engine States
#alias 8 	:	ENGINE_WAIT


sub ObjectMain
	switch Object.State
	case ACTFINISH_INIT
		// Setup initial values such as text positions
		
		// "SONIC GOT" is gonna come from the left, while all the other text slides in from the right
		Object.LineXPos0 = -799
		Object.LineXPos1 = 0x490
		Object.LineXPos2 = 0x4E7
		Object.LineXPos3 = 0x527
		Object.LineXPos4 = 0x57A

#platform: Use_Standalone
		Object.State = ACTFINISH_SLIDEIN
#endplatform
		
		// Calculate Time Bonus
		switch Stage.Minutes
		case 0
			if Stage.Seconds < 30
				// 0:00 - 0:29 - Wow that's fast, get a Mega Bonus!
				Object.TimeBonus = 50000
			else
				if Stage.Seconds < 45
					// 0:30 - 0:44
					Object.TimeBonus = 10000
				else
					// 0:45 - 0:59
					Object.TimeBonus = 5000
				end if
			end if
			break
			
		case 1
			if Stage.Seconds < 30
				// 1:00 - 1:29
				Object.TimeBonus = 4000
			else
				// 1:30 - 1:59
				Object.TimeBonus = 3000
			end if
			break
			
		case 2
			// 2:00 - 2:59
			Object.TimeBonus = 2000
			break
			
		case 3
			// 3:00 - 3:59
			Object.TimeBonus = 1000
			break
			
		case 4
			// 4:00 - 4:59
			Object.TimeBonus = 500
			break
			
		case 5
			// 5:00 - 5:59
			Object.TimeBonus = 100
			break
			
		// Anything after that, you get nothing, you lose!
		
		end switch
		
#platform: Use_Origins
		// If you Time Over'd, no Time Bonus either of course
		if game.timeOver != false
			Object.TimeBonus = 0
		end if
#endplatform
		
		// Ring Bonus calculation is far easier - just take the Player's ring count and multiply that by 100
		Object.RingBonus  = Player.Rings
		Object.RingBonus *= 100

#platform: Use_Origins
		// Find the Present version of the current stage
		Object.StagePosP = Stage.ListPos
		switch HUD.CurrentTimePeriod
		case TIME_PRESENT
			break
			
		case TIME_PAST
			Object.StagePosP--
			break
			
		case TIME_GOOD_FUTURE
			Object.StagePosP -= 2
			break
			
		case TIME_BAD_FUTURE
			Object.StagePosP -= 3
			break
			
		end switch
		
		// If in a Mission, we don't need Act Results
		if game.playMode == BOOT_PLAYMODE_MISSION
			Object.State = ACTFINISH_NULL
			// Back it up a bit
			Stage.ListPos = Object.StagePosP
		else
			// In Boss Rush, we don't need Act Results either
			if game.playMode == BOOT_PLAYMODE_BOSSRUSH
				Object.State = ACTFINISH_NULL
			else
				// We're in a normal mode, let's just show the Results normally
				Object.State = ACTFINISH_SLIDEIN
			end if
		end if
		
		// Send to the Engine how many Enemies have been destroyed so far
		game.callbackParam0 = StageStatsUsabilityParam1	// Enemies destroyed by any means
		game.callbackParam1 = StageStatsUsabilityParam2	// Enemies destroyed by rolling
		game.callbackParam2 = 0
		EngineCallback(NOTIFY_STATS_ENEMY)
		
		// Send to the Engine how many Rings the Player has
		game.callbackParam0 = Player.Rings
		EngineCallback(NOTIFY_STATS_RING)
		
		// Signal to the Engine that the current level is over
		EngineCallback(NOTIFY_ACT_FINISH)
		if Stage.PlayerListPos == PLAYER_KNUCKLES
			if Good_Future == true
				EngineCallback(NOTIFY_STATS_SAVE_FUTURE)
			end if
		end if
		
		// Reset loads of stuff...
		StageStatsUsabilityParam1 = 0
		StageStatsUsabilityParam2 = 0
		StageStatsUsabilityParam3 = 0
		StageStatsUsabilityParam4 = 0
		StatsUsabilityParam1	  = 0
		StatsUsabilityParam2	  = 0
		StatsUsabilityParam3	  = 0
		StatsUsabilityParam4	  = 0
#endplatform
		break
		
	case ACTFINISH_SLIDEIN
		
		// Get a base Position of 60 pixels off centre screen
		TempValue0  = Screen.CenterX
		TempValue0 -= 68
		
		// Update position of the "SONIC GOT" line
		if Object.LineXPos0 < TempValue0
			Object.LineXPos0 += 16
			if Object.LineXPos0 > TempValue0
				// Past the max, enforce it
				Object.LineXPos0 = TempValue0
				
			end if
		else
			// Just stay put for now
			Object.LineXPos0 = TempValue0
		end if
		
		// Update Position of the "THROUGH Zone" line
		TempValue0 -= 32
		if Object.LineXPos1 > TempValue0
			Object.LineXPos1 -= 16
			if Object.LineXPos1 < TempValue0
				// Enforce a minimum
				Object.LineXPos1 = TempValue0
			end if
		else
			// Hold!
			Object.LineXPos1 = TempValue0
		end if
		
		// The Score, Ring, and Time bonuses are all around the same X Position
		TempValue0 += 9
		
		// Score Line
		if Object.LineXPos2 > TempValue0
			Object.LineXPos2 -= 16
			if Object.LineXPos2 < TempValue0
				Object.LineXPos2 = TempValue0
			end if
		else
			Object.LineXPos2 = TempValue0
		end if
		
		// Ring Bonus Line
		if Object.LineXPos3 > TempValue0
			Object.LineXPos3 -= 16
			if Object.LineXPos3 < TempValue0
				Object.LineXPos3 = TempValue0
			end if
		else
			Object.LineXPos3 = TempValue0
		end if
		
		// Time Bonus line
		if Object.LineXPos4 > TempValue0
			Object.LineXPos4 -= 16
			if Object.LineXPos4 < TempValue0
				Object.LineXPos4 = TempValue0
			end if
		else
			Object.LineXPos4 = TempValue0

			// Proceed with the Act Results, now that everything's in position
			Object.State = ACTFINISH_DISPLAYTALLY
			Object.Timer = 0
		end if
		break
		
	case ACTFINISH_DISPLAYTALLY
		Object.Timer++
		
		// The two soundtracks have different Zone Complete lengths
		if Options.Soundtrack == OST_JP
			if Object.Timer > JP_ZONECOMPLETE_LENGTH
				
				// Proceed, now that the Jingle's over
				
				Object.Timer = 0
				
				Object.State = ACTFINISH_TALLYUP
				
				// See if the Paradise Found achievement should be unlocked
				if Stage.PlayerListPos == PLAYER_SONIC_A	// PLAYER_SONIC in origins
					if HUD.CurrentTimePeriod == TIME_GOOD_FUTURE
						if Stage.DebugMode == false
							SetAchievement(2, 100)
						end if
					end if
				end if
				
			end if
		else
			if Object.Timer > US_ZONECOMPLETE_LENGTH
				
				// It's now over, proceed with the Results
				
				Object.Timer = 0
				
				Object.State = ACTFINISH_TALLYUP
				
				// See if the Paradise Found achievement should be unlocked
				if Stage.PlayerListPos == PLAYER_SONIC_A	// PLAYER_SONIC in origins
					if HUD.CurrentTimePeriod == TIME_GOOD_FUTURE
						if Stage.DebugMode == false
							SetAchievement(2, 100)
						end if
					end if
				end if
				
			end if
		end if
		break
		
	case ACTFINISH_TALLYUP
		
		// Tally up the Ring Bonus and Time Bonus simultaneously
		
		if Object.RingBonus > 0
			Object.RingBonus -= 100
			Player.Score += 100
		end if
		
		if Object.TimeBonus > 0
			Object.TimeBonus -= 100
			Player.Score += 100
		end if
		
		// See if they're both over
		
		CheckGreater(Object.RingBonus, 0)
		TempValue0  = CheckResult
		CheckGreater(Object.TimeBonus, 0)
		TempValue0 |= CheckResult
		
		if TempValue0 == true
			
			// If they're not done yet, then play the Tally SFX
			
			Object.Timer++
			
			if Object.Timer == 2
				PlaySfx(SFX_G_SCOREADD, false)
				Object.Timer = 0
			end if
			
		else
			
			// They're both over now, go over now
			
			Object.State = ACTFINISH_DISPLAYFINAL
			Object.Timer = 0
			
			// Ka-ching!
			PlaySfx(SFX_G_SCORETOTAL, false)
			
		end if
		break
		
	case ACTFINISH_DISPLAYFINAL
		
		// Pause for a moment, to let the Player see what they got
		
		Object.Timer++
		
		if Object.Timer == 160
#platform: Use_Origins
			// Check if the player is replaying the stage from My Data & Rankings
			if game.oneStageFlag != false
				// If needed, let the Player retry the stage
				Object.StagePosP    = Stage.ListPos
				game.callbackResult = -1				// Reset any callback result
				game.callbackParam0 =  1				// 0 - Normal Retry, anything else - Show current and best time
				game.callbackParam1 =  Object.StagePosP	// Get current stage
				game.callbackParam2 =  0				// Unknown
				EngineCallback(NOTIFY_STAGE_RETRY)
				
				Object.Timer = 0
				// Go over to the holdover state and wait for the result
				Object.State = ACTFINISH_HOLDOVERRESTART
			else
				// Nope, everything can be resumed normally from here
				Object.Timer = 0
				Object.State = ACTFINISH_FADEOUT
			end if
#endplatform

#platform: Use_Standalone
			Object.Timer = 0
			Object.State = ACTFINISH_FADEOUT
#endplatform

			// If the Player's a Blank Object, then that means they entered a Special Ring
			if Player.Type == TypeName[Blank Object]
				PlaySfx(SFX_G_SPECIALWARP, false)
			end if
		end if
		break
		
	case ACTFINISH_FADEOUT
		if Player.Type == TypeName[Blank Object]
			// Special Stage!
			Object.Timer += 8
			// Use kinda-white to fade out, rather than black
			SetScreenFade(208, 255, 224, Object.Timer)

#platform: Use_Standalone
			if Engine.TrialMode == true
				if Object.Timer == 1016
					EngineCallback(CALLBACK_TRIAL_ENDED)
				end if
			end if
#endplatform

			if Object.Timer == 1024
				// Set Fade_Colour to be off-white (0xD0FFE0)
				Fade_Colour   = 208
				Fade_Colour <<= 16
				TempValue0    = 255
				TempValue0  <<= 8
				Fade_Colour  += TempValue0
				Fade_Colour  += 224
				
				// Reset more stuff
				Player.Direction = FACING_RIGHT
				Object.Timer	 = 0
				LampPost.Check	 = 0

				Good_Future_Count += Good_Future
				Good_Future		   = false

				Transporter_Destroyed = false
				MetalSonic_Destroyed  = false
				
				if Stage.ActNo == 2
					if Good_Future_Count < 2
						Stage.ListPos++
					end if
				end if
				
				if Stage.ActNo == 3
					Good_Future_Count = 0
				end if
				
				// Get the Stage List Pos of the next stage's Present version
				switch HUD.CurrentTimePeriod
				case TIME_PRESENT
					Stage.ListPos += 4
					break
					
				case TIME_PAST
					Stage.ListPos += 3
					break
					
				case TIME_GOOD_FUTURE
					Stage.ListPos += 2
					break
					
				case TIME_BAD_FUTURE
					Stage.ListPos++
					break
					
				end switch
				
				if Options.GameMode == MODE_SAVEGAME
					ArrayPos1   = Options.SaveSlot
					ArrayPos1 <<= 3
					SaveRAM[ArrayPos1] = Stage.PlayerListPos
					ArrayPos1++
					SaveRAM[ArrayPos1] = Player.Lives
					ArrayPos1++
					SaveRAM[ArrayPos1] = Player.Score
					ArrayPos1++
					SaveRAM[ArrayPos1] = Stage.ListPos
					// Add 101 to the Stage List Pos to signify that it's a Special Stage save
					SaveRAM[ArrayPos1] += 101
					ArrayPos1++
					SaveRAM[ArrayPos1] = SpecialStage.TimeStones
					ArrayPos1++
					SaveRAM[ArrayPos1] = SpecialStage.ListPos
					ArrayPos1++
					SaveRAM[ArrayPos1] = Player.ScoreBonus
									
					ArrayPos1++
					SaveRAM[ArrayPos1]   = MetalSonic_List
					SaveRAM[ArrayPos1] <<= 16
					SaveRAM[ArrayPos1]  += Good_Future_List
					
					WriteSaveRAM()
				end if
				
#platform: Use_Origins
				recScore = Player.Score
				SpecialStage.NextZone = Stage.ListPos
				// Origins got the SPECIAL_STAGE alias swapped with BONUS_STAGE
				Stage.ActiveList = 3
				Stage.ListPos    = SpecialStage.ListPos
				
				// Check if the player is replaying the stage from My Data & Rankings
				if game.oneStageFlag != false
					Stage.ActiveList = REGULAR_STAGE
					Stage.ListPos    = Object.StagePosP

					Object.State = ACTFINISH_WAITFORCALLBACK
				else
					TempValue0 = Engine.TrialMode
					if Stage.ListPos >= Stage.ListSize
						TempValue0 = true
					end if
					
					if TempValue0 == false
						LoadStage()
					else
						Stage.ActiveList = PRESENTATION_STAGE
						Stage.ListPos    = STAGE_P_TITLE

						Engine.State = ENGINE_WAIT
					end if
				end if
#endplatform

#platform: Use_Standalone
				SpecialStage.NextZone = Stage.ListPos
				Stage.ListPos	 = SpecialStage.ListPos
				Stage.ActiveList = SPECIAL_STAGE

				TempValue0 = Engine.TrialMode
				if Stage.ListPos >= Stage.ListSize
					TempValue0 = true
				end if
				
				if TempValue0 == false
					LoadStage()
				else
					Stage.ActiveList = PRESENTATION_STAGE
					Stage.ListPos = STAGE_P_TITLE
					LoadStage()
				end if
#endplatform
			end if
		else
			// We didn't enter a Special Ring, we're staying in normal stages
			Object.Timer += 4
			SetScreenFade(0, 0, 0, Object.Timer)
			
			if Engine.TrialMode == true
				if Object.Timer == 380
					EngineCallback(CALLBACK_TRIAL_ENDED)
				end if
			end if
			
			if Object.Timer == 384
				// Set Fade_Colour to be black
				Fade_Colour = 0
				
				// Reset some cool values
				Object.Timer   = 0
				LampPost.Check = 0

				Player.Direction = FACING_RIGHT

				Good_Future_Count += Good_Future
				Good_Future		   = false

				Transporter_Destroyed = false
				MetalSonic_Destroyed  = false
				
				if Stage.ActNo == 2
					if Good_Future_Count < 2
						Stage.ListPos++
					end if
				end if
				
				if Stage.ActNo == 3
					Good_Future_Count = 0
				end if
				
				// Get the Stage ID of the next stage's starting version
				switch HUD.CurrentTimePeriod
				case TIME_PRESENT
					Stage.ListPos += 4
					break
					
				case TIME_PAST
					Stage.ListPos += 3
					break
					
				case TIME_GOOD_FUTURE
					Stage.ListPos += 2
					break
					
				case TIME_BAD_FUTURE
					Stage.ListPos++
					break
					
				end switch
				
				if Options.GameMode == MODE_SAVEGAME
					ArrayPos1   = Options.SaveSlot
					ArrayPos1 <<= 3
					SaveRAM[ArrayPos1] = Stage.PlayerListPos
					ArrayPos1++
					SaveRAM[ArrayPos1] = Player.Lives
					ArrayPos1++
					SaveRAM[ArrayPos1] = Player.Score
					ArrayPos1++
					SaveRAM[ArrayPos1] = Stage.ListPos
					SaveRAM[ArrayPos1]++
					ArrayPos1++
					SaveRAM[ArrayPos1] = SpecialStage.TimeStones
					ArrayPos1++
					SaveRAM[ArrayPos1] = SpecialStage.ListPos
					ArrayPos1++
					SaveRAM[ArrayPos1] = Player.ScoreBonus
					
					ArrayPos1++
					SaveRAM[ArrayPos1]   = MetalSonic_List
					SaveRAM[ArrayPos1] <<= 16
					SaveRAM[ArrayPos1]  += Good_Future_List
					
					WriteSaveRAM()
				end if

#platform: Use_Origins
				recScore = Player.Score
				
				// Check if the player is replaying the stage from My Data & Rankings
				if game.oneStageFlag != false
					Stage.ActiveList = REGULAR_STAGE
					Stage.ListPos    = Object.StagePosP
					Object.State     = ACTFINISH_WAITFORCALLBACK
				else
					if Options.GameMode == MODE_TIMEATTACK
						if Stage.PlayerListPos == PLAYER_SONIC
							// Get the act number
							TempValue0   = Stage.ListPos
							TempValue0  %= 10
							TempValue0 >>= 2
							
							// Get the current Round
							TempValue1  = Stage.ListPos
							TempValue1 /= 10
							TempValue1 *= 3
							
							// Add them together to get the stage ID
							TempValue0 += TempValue1
							TempValue0++
							
							// And now, tally up all the time
							
							TempValue1  = Stage.Seconds
							TempValue1 *= 100
							
							TempValue2  = Stage.Minutes
							TempValue2 *= 6000
							
							TempValue1 += TempValue2
							TempValue1 += Stage.MilliSeconds
							
							// Enter all that data into the Leaderboard, make your mark on the world!
							SetLeaderboard(TempValue0, TempValue1)
						end if
						
						// Tally up all the results, into one single large number
						TimeAttack.Result  = Stage.Seconds
						TimeAttack.Result *= 100
						
						TempValue0  = Stage.Minutes
						TempValue0 *= 6000
						
						TimeAttack.Result += TempValue0
						TimeAttack.Result += Stage.MilliSeconds
						
						Stage.ActiveList = PRESENTATION_STAGE
						Stage.ListPos    = STAGE_P_TATTACK
						
						LoadStage()
					else
						// Don't lie to me SEGA, there was a demo for origins planned!!!
						if Options.GameMode < MODE_TRIAL
							TempValue0 = Engine.TrialMode
						else
							TempValue0 = false
						end if
						
						if Stage.ListPos >= Stage.ListSize
							TempValue0 = true
						end if
						
						if TempValue0 == false
							LoadStage()
						else
							if Engine.TrialMode == true
								Stage.ActiveList = PRESENTATION_STAGE
								Stage.ListPos    = STAGE_P_DOWNLOADSCREEN
								LoadStage()
							else
								Engine.State = ENGINE_WAIT
							end if
						end if
					end if
				end if
#endplatform

#platform: Use_Standalone
				// this check can only happen in mobile
				if Options.GameMode == MODE_TRIAL
					// Set Trial Recoerds
					TimeAttack.Result  = Stage.Seconds
					TimeAttack.Result *= 100

					TempValue0  = Stage.Minutes
					TempValue0 *= 6000
					
					TimeAttack.Result += TempValue0
					TimeAttack.Result += Stage.MilliSeconds

					switch TimeAttack.Round
					case 0
						if TimeAttack.Result < SaveRAM[48]		// PPZ Record
							SaveRAM[48] = TimeAttack.Result
						end if
						break
					case 1
						if TimeAttack.Result < SaveRAM[49]		// QQZ Record
							SaveRAM[49] = TimeAttack.Result
						end if
						break
					end switch
					WriteSaveRAM()
					Stage.ActiveList = PRESENTATION_STAGE
					Stage.ListPos	 = STAGE_P_DOWNLOADSCREEN
				end if

				if Options.GameMode == MODE_TIMEATTACK
					TimeAttack.Result  = Stage.Seconds
					TimeAttack.Result *= 100
					TempValue0  = Stage.Minutes
					TempValue0 *= 6000
					TimeAttack.Result += TempValue0
					TimeAttack.Result += Stage.MilliSeconds
					Stage.ActiveList   = PRESENTATION_STAGE
					Stage.ListPos	   = STAGE_P_TATTACK
					LoadStage()
				else
					// this check can only happen in mobile
					if Options.GameMode < MODE_TRIAL
						TempValue0 = Engine.TrialMode
					else
						TempValue0 = false
					end if

					if Stage.ListPos >= Stage.ListSize	// tldr - check if you are playing a trial
						TempValue0 = true
					end if

					if TempValue0 == false
						LoadStage()
					else
						Stage.ActiveList = PRESENTATION_STAGE
						Stage.ListPos	 = STAGE_P_TITLE
						LoadStage()
					end if
				end if
#endplatform
			end if
		end if
		break
		
#platform: Use_Origins
	case ACTFINISH_HOLDOVERRESTART
		// Wait and see, does the Player want to restart the stage?
		if game.callbackResult >= 0
			Object.Timer = 0
			Object.State = ACTFINISH_FADEOUT
		end if
		break
		
	case ACTFINISH_WAITFORCALLBACK
		SetScreenFade(0, 0, 0, 255)
		break
#endplatform
	end switch
end sub


sub ObjectDraw
	// First two lines are dependant on if Sonic made a Good Future or not
	// Regardless of the path taken here, TempValue0 afterwards should be where the "Zone" text is drawn,
	// in order for the following code to be done correctly
	if Good_Future == false
		// No Good Future here, just do the normal results
		
		// First line - "Sonic GOT"
		DrawSpriteScreenXY(0, Object.LineXPos0, 65)
		
		// Second line - "THROUGH"
		DrawSpriteScreenXY(4, Object.LineXPos1, 89)
		
		// To the right of that, draw "Zone"
		TempValue0 = Object.LineXPos1
		TempValue0 += 128
		DrawSpriteScreenXY(5, TempValue0, 89)
	else
		// We made a Good Future!
		// Let's used the altered version of the text to let the Player know
		
		// Draw "SONIC MADE A GOOD" for the first line
		// (For Knux, this is just "MADE A GOOD", with his name being drawn separately down below)
		DrawSpriteScreenXY(20, Object.LineXPos0, 65)

#platform: Use_Origins
		if Stage.PlayerListPos == PLAYER_KNUCKLES
			// "KNUCKLES"
			DrawSpriteScreenXY(22, Object.XPos, 65)
		end if
#endplatform
		
		// Then, comes "FUTURE IN"
		DrawSpriteScreenXY(21, Object.LineXPos1, 89)
		
		// And to the right of that, draw the "Zone" text
		TempValue0 = Object.LineXPos1
		TempValue0 += 140
		DrawSpriteScreenXY(5, TempValue0, 89)
	end if
	
	// From where the "Zone" text was drawn, draw the Act Number next to it
	TempValue0 += 64
	DrawSpriteScreenXY(Stage.ActNo, TempValue0, 89)
	
	// Draw the Score text
	DrawSpriteScreenXY(6, Object.LineXPos2, 121)
	
	// And then to the right of that, draw the Score numbers
	TempValue0 = Object.LineXPos2
	TempValue0 += 163
	DrawNumbers(10, TempValue0, 121, Player.Score, 6, 8, false)
	
	// The fourth line holds the Rings text
	DrawSpriteScreenXY(7, Object.LineXPos3, 145)
	
	// Append "Bonus" to the end of that Rings text
	TempValue0 = Object.LineXPos3
	TempValue0 += 40
	DrawSpriteScreenXY(9, TempValue0, 145)
	
	// And on the same line, draw the Ring Bonus
	TempValue0 += 123
	DrawNumbers(10, TempValue0, 145, Object.RingBonus, 5, 8, false)
	
	// The fifth line holds the Time Bonus
	
	// So, draw the "Time" sprite first
	DrawSpriteScreenXY(8, Object.LineXPos4, 169)
	
	// And then similarly, append "Bonus" to that
	TempValue0 = Object.LineXPos4
	TempValue0 += 40
	DrawSpriteScreenXY(9, TempValue0, 169)
	
	//And now, draw the Time Bonus numbers at the end of the line
	TempValue0 += 123
	DrawNumbers(10, TempValue0, 169, Object.TimeBonus, 5, 8, false)
end sub


sub ObjectStartup
	// Load the appropriate sheet based on the current character
	if Stage.PlayerListPos == PLAYER_SONIC_A
		LoadSpriteSheet("Global/Display.gif")
	end if
	if Stage.PlayerListPos == PLAYER_TAILS_A
		LoadSpriteSheet("Global/Display_t.gif")
	end if

#platform: Use_Origins
	if Stage.PlayerListPos == PLAYER_KNUCKLES
		LoadSpriteSheet("Global/Display_k.gif")
	end if
	if Stage.PlayerListPos == PLAYER_AMY
		LoadSpriteSheet("Global/Display_a.gif")
	end if
	// Act Results Frames
	
	if Stage.PlayerListPos == PLAYER_KNUCKLES
		// 0 - "KNUCKLES GOT"
		SpriteFrame(-27, 0, 191, 16, 35, 257)
	else
		// 0 - "SONIC GOT"
		SpriteFrame(0, 0, 136, 16, 0, 206)
	end if
#endplatform

#platform: Use_Standalone
	// 0 - "SONIC GOT"
	SpriteFrame(0,   0,   136, 16, 0,   206)
#endplatform

	
	// 1-3 - Act Numbers
	SpriteFrame(0,   0,   8,   16, 194, 223)
	SpriteFrame(0,   0,   16,  16, 203, 223)
	SpriteFrame(0,   0,   16,  16, 220, 223)
	
	// 4 - "THROUGH"
	SpriteFrame(0,   0,   113, 16, 137, 206)
	
	// 5 - "Zone"
	SpriteFrame(0,   0,   56,  16, 137, 223)
	
	// 6 - Score text
	SpriteFrame(0,   0,   39,  11, 1,   1)
	
	// 7 - Rings text
	SpriteFrame(0,   0,   31,  11, 1,   33)
	
	// 8 - Time text
	SpriteFrame(0,   0,   31,  11, 1,   17)
	
	// 9 - Bonus text
	SpriteFrame(0,   0,   41,  11, 1,   107)
	
	// 10-19 - Numbers
	SpriteFrame(0,   0,   8,   11, 1,   50)
	SpriteFrame(0,   0,   8,   11, 10,  50)
	SpriteFrame(0,   0,   8,   11, 19,  50)
	SpriteFrame(0,   0,   8,   11, 28,  50)
	SpriteFrame(0,   0,   8,   11, 1,   62)
	SpriteFrame(0,   0,   8,   11, 10,  62)
	SpriteFrame(0,   0,   8,   11, 19,  62)
	SpriteFrame(0,   0,   8,   11, 28,  62)
	SpriteFrame(0,   0,   8,   11, 1,   74)
	SpriteFrame(0,   0,   8,   11, 10,  74)

#platform: Use_Standalone
	// 20 - "SONIC MADE A GOOD"
	SpriteFrame(-60, 0, 256,   16, 0,   240)
	
	// 21 - "FUTURE IN"
	SpriteFrame(-12, 0, 136,   16, 0,   223)
#endplatform

#platform: Use_Origins
	if Stage.PlayerListPos == PLAYER_KNUCKLES
		// 20 - "         MADE A GOOD"
		SpriteFrame(-41, 0, 256, 16, 0, 240)
		// 21 - "FUTURE IN"
		SpriteFrame(-12, 0, 136, 16, 0, 223)
		// 22 - "KNUCKLES"
		SpriteFrame(-79, 0, 127, 16, 35, 257)
	else
		// 20 - "SONIC MADE A GOOD"
		SpriteFrame(-60, 0, 256, 16, 0, 240)
		// 21 - "FUTURE IN"
		SpriteFrame(-12, 0, 136, 16, 0, 223)
	end if

#endplatform
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(0, 0, 113, 16, 137, 206)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub